www.gusucode.com > VC++ 窗体局部挖洞透明-源码程序 > VC++ 窗体局部挖洞透明-源码程序/code/Show91MobileDlg.cpp
// Show91MobileDlg.cpp : implementation file // Download by http://www.NewXing.com #include "stdafx.h" #include "Show91Mobile.h" #include "Show91MobileDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CShow91MobileDlg dialog CShow91MobileDlg::CShow91MobileDlg(CWnd* pParent /*=NULL*/) : CDialog(CShow91MobileDlg::IDD, pParent) { //{{AFX_DATA_INIT(CShow91MobileDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CShow91MobileDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CShow91MobileDlg) DDX_Control(pDX, IDC_STATIC1, m_Picture); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CShow91MobileDlg, CDialog) //{{AFX_MSG_MAP(CShow91MobileDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_LBUTTONDOWN() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CShow91MobileDlg message handlers BOOL CShow91MobileDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here //----------- //隐藏WINDOWS系统任务栏 ::ShowWindow (::FindWindow("Shell_TrayWnd",NULL),SW_HIDE); char m_pAppRootPath[256]={0}; ::GetModuleFileName(NULL,m_pAppRootPath,MAX_PATH); (_tcsrchr(m_pAppRootPath, _T('\\')))[1] = 0;//删除文件名,只获得路径 CString str; str=m_pAppRootPath; str+="\\Show91Mobile.bmp"; HBITMAP m_hbitmap = (HBITMAP)::LoadImage(GetModuleHandle(NULL),str, IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_DEFAULTSIZE|LR_DEFAULTCOLOR); m_Picture.SetBitmap(m_hbitmap); CRect rect; m_Picture.GetWindowRect(rect); //m_Picture.set CRect m_rect; GetWindowRect(m_rect); CRect desktoprect; GetDesktopWindow()->GetWindowRect(&desktoprect); int x=0; int y=0; x=desktoprect.Width(); y=desktoprect.Height(); MoveWindow(CRect(0,0,x,y)); ShowWindow(TRUE); //CenterWindow(); //----------- CRect rect1; GetWindowRect(rect1); CRect rect2; GetClientRect(rect2); ClientToScreen(rect2); CRgn rgn1; rgn1.CreateRectRgn(0, 0, x, y); int nwidth=480;//洞宽 int nhight=768;//洞高 CRgn rgn2; //洞开在屏中间部份 rgn2.CreateRectRgn((x-nwidth)/2, (y-nhight)/2, (x-nwidth)/2+nwidth, (y-nhight)/2+nhight); CRgn rgn; rgn.CreateRectRgn(0, 0, 1, 1); rgn.CombineRgn(&rgn1, &rgn2, RGN_DIFF); //设置窗口区域 SetWindowRgn((HRGN)rgn,TRUE); ModifyStyleEx (WS_EX_APPWINDOW,WS_EX_TOOLWINDOW|WS_EX_TOPMOST ); const CWnd * pWndInsertAfter; pWndInsertAfter = &wndTopMost; SetWindowPos(pWndInsertAfter,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE); return TRUE; // return TRUE unless you set the focus to a control } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CShow91MobileDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CShow91MobileDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CShow91MobileDlg::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default if(point.x>824 && point.y>450 && point.x<955 && point.y<505) { CloseWindow(); } CDialog::OnLButtonDown(nFlags, point); } BOOL CShow91MobileDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message == WM_KEYDOWN && pMsg->wParam == 0x0d) //ENTER按键 { CloseWindow(); } if(pMsg->message == WM_KEYDOWN && pMsg->wParam == 0x1b) //ESC按键 { CloseWindow(); } return CDialog::PreTranslateMessage(pMsg); } BOOL CShow91MobileDlg::CloseWindow() { SendMessage(WM_CLOSE); Sleep(10); //恢复WINDOWS系统任务栏正常显示 ::ShowWindow (::FindWindow("Shell_TrayWnd",NULL),SW_SHOW); HWND hWnd=::FindWindow(NULL,"Android手机助手 v1.5.8.98"); if(hWnd) { ::SetWindowPos(hWnd,HWND_TOPMOST,0,0,800,500,SWP_SHOWWINDOW); keybd_event(VK_ESCAPE,NULL,NULL,NULL); keybd_event(VK_ESCAPE,NULL,KEYEVENTF_KEYUP,NULL); } return TRUE; }